package com.xiaohudie.Ioliu;

import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;

import java.io.*;

/**
 * @Author xiao hu die
 * @Date 2022/1/8 20:36
 * @Version 1.0
 */
/**InputStreamReader*/
public class Test07 {
 public static void main(String[] args) {

 }
 @SneakyThrows
 @Test
 public void test01(){
  String filePath ="D:\\sorry.txt";
  BufferedReader bufferedInputStream =null;
   bufferedInputStream = new BufferedReader(new FileReader(filePath));
   String line =null;
  String s = bufferedInputStream.readLine();
  System.out.println(s);
 }
 @SneakyThrows
 @Test
 public void test02(){
  String filepath ="D:\\sorry.txt";
  InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(filepath),"gbk");
  BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
  String s = bufferedReader.readLine();
  System.out.println(s);
 bufferedReader.close();
 }
 @SneakyThrows
 @Test
 public void test03(){
  String filePath ="D:\\ld2.txt";
  OutputStreamWriter outputStreamWriter =new OutputStreamWriter(new FileOutputStream(filePath),"gbk");
  outputStreamWriter.write("hi,刘碟");
  outputStreamWriter.close();
  System.out.println("按照GBK编码" +"保存文件成功" );

 }
}
